package com.memento;

import com.memento.backup.Memento;
import com.memento.cache.Caretaker;
import com.memento.entity.Role;

public class Test {

    public static void main(String[] args) {
        Role role = new Role(100, 100);
        System.out.println("角色当前状态[最初]：" + role.toString());
        // 记下存档
        Memento memento = role.createMemento();
        Caretaker historyMemento = new Caretaker();
        historyMemento.addMemento("存档一", memento);
        // 闯关失败
        role.setBlood(0);
        role.setMana(0);
        System.out.println("角色当前状态[失败]：" + role.toString());
        // 恢复存档
        Memento mem = historyMemento.getMemento("存档一");
        role.restoreMemento(mem);
        System.out.println("角色当前状态[恢复]：" + role.toString());
    }

}
